Quitting an Application
Eventually the user will quit your application, usually by choosing Quit from the File menu (or by pressing the usual keyboard equivalent, Command-Q). At that time, you should close all windows, release any memory you still are holding, and exit your main event loop. Listing 9-4 shows theDoQuit
routine called by the Venn Diagrammer application when the user chooses Quit from the File menu.Listing 9-4 Quitting your application
PROCEDURE DoQuit; VAR myWindow: WindowPtr; BEGIN myWindow := FrontWindow; {close all windows} WHILE myWindow <> NIL DO BEGIN DoUpdate(myWindow); {force redrawing window} DoCloseWindow(myWindow); myWindow := FrontWindow; END; gDone := TRUE; {set flag to exit main event loop} END;TheDoQuit
procedure simply closes all windows belonging to the application and then sets the application global variablegDone
to indicate that the user has finished using the application. Recall that the main event loop (Listing 4-4 on page 77) terminates whengDone
isTRUE
.
- Note
- The Process Manager automatically deallocates your application partition and closes all windows when your application terminates. As a result, the Venn Diagrammer application could simply have set
gDone
toTRUE
in response to the Quit command. However,DoQuit
illustrates how to close all windows because your version ofDoCloseWindow
might need to prompt the user to save any unsaved data in document windows currently on the desktop.![]()